package com.ih.controller;

import com.ih.pojo.Inventory;
import com.ih.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @ClassName InventoryController
 * @Description
 * @Author xiaozhang
 * @date 2023-05-07
 */
@Controller
public class InventoryController {
    @Autowired
    private InventoryService inventoryService;
    @RequestMapping("/toInventory")
    public String getListInventory(Model model){
        List<Inventory> inventories = inventoryService.listInventory();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (int i = 0; i < inventories.size(); i++) {
            inventories.get(i).setAddTime_1(dateFormat.format(inventories.get(i).getAddTime()));
        }
        model.addAttribute("inventories",inventories);
        return "ListInventory";
    }
    @RequestMapping("/getListInventory")
    @ResponseBody
    public List<Inventory> getList(){
        List<Inventory> inventories = inventoryService.listInventory();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (int i = 0; i < inventories.size(); i++) {
            inventories.get(i).setAddTime_1(dateFormat.format(inventories.get(i).getAddTime()));
        }

        return inventories;
    }
}
